﻿import A2.utils.uMC;
import A2.btnEffect.BEV3;
import A2.utils.uPos;
import A2.utils.uTween;
import mx.utils.Delegate;
import mx.transitions.Tween;
import mx.transitions.easing.*;
import com.darronschall.DynamicRegistration;
import gs.*; 
import A2.HandDoBtn;
import A2.utils.uString; 
import mx.utils.ObjectCopy;

/**
 * ...
 * @author wangjun
 */
class A2.ui.cluePannelV2 extends A2.ui.Pannel
{
	var btnPart	:MovieClip;
	var tfPart	:MovieClip;
	var tf		:TextField;
	var btn_ruler	:MovieClip;
	var btn_real	:MovieClip;
	var scope	:MovieClip;
	var ntf		:MovieClip;
	var bg		:MovieClip;
	
	var btn_arr	:Array = [];
	var func_arr:Array = [];
	var autoClose_arr:Array = [];
	var callback:Function; 
	var iconCtnr:MovieClip;
	
	var mode:String;
	
	public function cluePannelV2 () 
	{
		super();
		
		tf.multiline = true;
		tf.selectable 	= false;
		btn_ruler 		= btnPart.ruler; 	
		
	} 

	//this._visible = false; 
 
	function show(scope:MovieClip, str:String) { 		 
		this.scope = (scope != null)? scope:null;
		trace(this.scope)
		if (this.scope == null) throw new Error( "!! A2.ui.cluePannelV2::show 缺少scope");
		 
		
		var arg_arr:Array = arguments;
		
		var vars:Object = new Object();
		if(arg_arr.length>2){
			var last_one = arg_arr[arg_arr.length - 1];
			if (last_one.constructor != String) {
				if (last_one.constructor==Object) {
					vars = ObjectCopy.copy(last_one);
					this.callback = (last_one.callback != null)?last_one.callback:null; 
				}else{
					trace("!!警告,Alert最后参数既不是String，又不是对象")
				}
			}
			 
				 var btns:Array 	= [];   
				 for (var i:Number = 2; i <arg_arr.length ; i++) 
				{
					var oo = arg_arr[i];
					if(oo.constructor==String){
						btns.push	(arg_arr[i]); 
					}
				}  
		}
		
		A2.btnEffect.uBtn.del(this);
		removeMovieClip(btn_real);
		btn_real 		= btnPart.createEmptyMovieClip('real',1); 
				 
	//------------------------  华丽的分割线 --------------------------  文本
		tf.text = uString.replace(str, '`', '\r'); 
		
		//ntf = 
		if(this.mode =="returnVV"){ 
			var now_dele:MovieClip = uMC.newMC(ntf);
		}else { 
			ntf = this.createEmptyMovieClip('ntf', 9999);
			ntf._x = tf._x;
			ntf._y = tf._y;
			var now_dele:MovieClip = uMC.newMC(ntf);
		}
		A2.utils.uBitmap.bmTxt(tf, now_dele);		
		//A2.utils.uBitmap.bmTxt(tf);		
		
	//------------------------  华丽的分割线 --------------------------  按钮 
		 
		 this.btn_arr 		= []; 
		 
		var realNum:Number 	= 0;
		var len:Number 	= btns.length;
		var Xpos:Number 	= 0;
		 
		
		for (var i:Number = 0; i < len; i++) 
		{
								
			var b = btn_real.attachMovie(btns[i], i.toString(), i); 
			if (b != null) {
				/*
				if (b.constructor == Button) {
					
					//trace( "注意!! A2.ui.cluePannelV2::show 所附加的MC是Button");
					
				}
				*/
				realNum++;
				b._x += Xpos;
				Xpos += b._width + 30;				
				
				btn_arr.push(b);
				b.label=btns[i]
				new BEV3(this, b,function(evt) {  
						evt['idt'] = evt.it.label;
						trace('this.callback - > '+this.callback);
						Delegate.create(this.scope, this.callback)(evt); 
						A2.btnEffect.uBtn.dummy(this);
						close();						 
					}
					
				) 
			}else {
				throw new Error( "附加失败!! A2.ui.cluePannelV2::show 请检查库链接 -> "+btns[i]);
			}
		}
		if (this.mode == 'wait') {			
			if (iconCtnr != null && iconCtnr._alpha > 0) {
					uTween.fadeOut(iconCtnr)
			}
			this.mode = 'returnVV';
		}
		if (vars.loadingIconID != null) {
			var dd:Number = this.getNextHighestDepth();
			iconCtnr = this.attachMovie(vars.loadingIconID, dd.toString(), dd);   
			if (iconCtnr != null) { 
				uPos.center(this.bg, this.iconCtnr);
				if (vars.loadingIconOffset != null) {
						 this.iconCtnr._x += vars.loadingIconOffset[0];
						 this.iconCtnr._y += vars.loadingIconOffset[1];
				}
				this.mode = 'wait';
			}else 
			{
				throw new Error( "附加失败!! A2.ui.cluePannelV2::show 请检查库链接 -> " + iconCtnr);
			} 
				
		}
		//Pos.centerMutiple(btn_ruler, btn_arr ); 
		
																	// 居中对齐
		uPos.center(btn_ruler, btn_real);
		btn_ruler._visible = false;
		 
		trace("this.mode = " + this.mode );
		if (this.mode == 'returnVV') { 
			this.mode = null;
		}else {
			this.open(true);	
		}
		 
	} 
	
}